﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BKO.DataAccesss;
using BKO.DataAccesss.Repositories;
using BKO.Domain.Model;
using BKO.Domain.Services;

namespace BKO.Services
{
	public class OtdelService : BaseService<IOtdel>, IOtdelService
	{
		public OtdelService(string connectionString)
			: base(new BaseRepository<IOtdel, OtdelEntity>(BKODataContextSingletone.GetInstance(connectionString)))
		{
		}

		public List<IOtdel> GetAllByFilial(int filialId, bool visible)
		{
			IQueryable<IOtdel> query = Repository.GetAll().Where(o => o.FilialId == filialId);

			if (!visible)
			{
				query = query.Where(o => o.ARHIV == 0);
			}
			query = query.OrderBy(o => ((OtdelEntity)o).FilialEntity.Name).OrderBy(o => o.Name);

			return query.ToList();
		}
	}
}
